from typing import List, Optional
from pydantic import BaseModel, EmailStr
from datetime import datetime

from app.schemas.user import UserBrief


# 商家图片基础模式
class MerchantImageBase(BaseModel):
    url: str
    description: Optional[str] = None
    is_cover: bool = False


# 创建商家图片模式
class MerchantImageCreate(MerchantImageBase):
    pass


# 商家图片模式
class MerchantImage(MerchantImageBase):
    id: int
    merchant_id: int
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        orm_mode = True


# 商家基础模式
class MerchantBase(BaseModel):
    name: str
    logo: Optional[str] = None
    description: Optional[str] = None
    address: Optional[str] = None
    phone: Optional[str] = None
    email: Optional[EmailStr] = None
    latitude: Optional[float] = None
    longitude: Optional[float] = None


# 创建商家模式
class MerchantCreate(MerchantBase):
    business_license: Optional[str] = None


# 更新商家模式
class MerchantUpdate(MerchantBase):
    name: Optional[str] = None
    business_license: Optional[str] = None
    is_active: Optional[bool] = None


# 商家简要信息模式
class MerchantBrief(BaseModel):
    id: int
    name: str
    logo: Optional[str] = None
    is_verified: bool

    class Config:
        orm_mode = True


# 商家详细信息模式
class Merchant(MerchantBase):
    id: int
    user_id: int
    business_license: Optional[str] = None
    is_verified: bool
    is_active: bool
    is_deleted: bool
    created_at: datetime
    updated_at: Optional[datetime] = None
    user: Optional[UserBrief] = None
    images: List[MerchantImage] = []

    class Config:
        orm_mode = True 